/**==================================================================
 * Copyright: Belongs to Cystc (org.cystc) 2013~2065
 * FileName: org.cystc.users.services.impl.UserServicesImpl.java
 * Description: 
 * Changes: 
 * Date                Author           Note
 * ===================================================================
 * 2013-3-10    Cysct(cystc@126.com)     Create file,implement function
 **===================================================================*/
package org.cystc.users.services.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.cystc.common.services.impl.BaseServicesImpl;
import org.cystc.users.dao.inter.UserDao;
import org.cystc.users.model.User;
import org.cystc.users.services.inter.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class UserServicesImpl extends BaseServicesImpl implements UserServices {

	private static final Logger LOGGER = Logger
			.getLogger(UserServicesImpl.class.getName());
	@Autowired
	private UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void add(User user) {
		if (user == null) {
			LOGGER.warn("the User which you passed is null");
			return;
		}
		LOGGER.debug("Adding the following user: " + user.getUsername() + ", "
				+ user.getPassword());
		userDao.add(user);
	}

	public void delete(User user) {
		if (user == null) {
			LOGGER.warn("the User which you passed is null");
			return;
		}
		LOGGER.debug("Deleteting the following user: " + user.getId() + ", "
				+ user.getUsername() + ", " + user.getPassword());
		userDao.delete(user);
	}

	public List<?> findAll() {
		LOGGER.debug("Getting all users");
		return userDao.findAll();
	}

	public List<?> findById(int id) {
		return userDao.findById(id);
	}

	public List<?> findByUsername(String username) {
		return userDao.findByUsername(username);
	}

	public void update(User user) {
		if (user == null) {
			LOGGER.warn("the User which you passed is null");
			return;
		}
		userDao.update(user);
	}

}
